<?php

m2import('phpinchains/psp/Tag.php');
m2import('phpinchains/tagsupport/CmsImage.php');

class cms_imageinfoHandler extends phpinchains_psp_Tag
{

    /**
     * Is a body tag (if false, body is ignored)
     */
    var $tagType = PSP_EMPTY_TAG;
    /**
     * Tag name in form namespace:tagname
     */
    var $tagName   = 'cms:imageinfo';

    var $requiredAttributes = array(
        'id'  => '(imageid:\d+|\d+)',
        'var' => '[\d\w_]+'
    );
    var $attributes = array(
    );

    function doStartTag()
    {
        if (preg_match('/imageid:(\d+)/', $this->getAttribute('id'), $matches)) {
            $id = $matches[1];
        } else {
            $id = $this->getAttribute('id');
        }

        $cmsimg = new CmsImage($id, $this->getAttribute('width'), $this->getAttribute('height'));
        $img = array(
            'width'     => $cmsimg->getOrigWidth(),
            'height'    => $cmsimg->getOrigHeight(),
            'url'       => $cmsimg->getUrl(),
            'mimetype'  => $cmsimg->getMimeType(),
            'size'      => $cmsimg->getFileSize(),
            'sizehr'    => $cmsimg->getFileSizeHR()
        );
        $this->actionform->set($this->getAttribute('var'), $img);
        return PSP_SKIP_BODY;
    }

    // In empty tag only necessary, if tag skips page, e.g. redirect -> no further processing needed
    function doEndTag()
    {
        //return PSP_SKIP_PAGE;
    }

}
?>